package com.example.cstr.controller;

import com.example.cstr.entity.Announcement;
import com.example.cstr.entity.Message;
import com.example.cstr.service.AnnouncementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

//这个类的所有方法返回的数据直接写给浏览器。（如果是对象转为json数据）
@RestController
@RequestMapping("/api/Announcement")
@Api(tags = "公告")
public class AnnouncementController {
    @Resource
    private AnnouncementService announcementService;

    @ApiOperation(value = "添加公告")
    @PostMapping("/add")
    public Message insertAnnouncement(Announcement announcement){
        return announcementService.insertSelective(announcement)>0?Message.success(null):Message.fail(null);
    }

    @ApiOperation(value = "删除公告")
    @DeleteMapping("/delete")
    public Message deleteAnnouncement(Integer anc_id){
        return announcementService.deleteByPrimaryKey(anc_id)>0?Message.success(null):Message.fail(null);
    }

    @ApiOperation(value = "修改公告")
    @PutMapping("/update")
    public Message updateAnnouncement(Announcement announcement){
        return announcementService.updateByPrimaryKeySelective(announcement)>0?Message.success(null):Message.fail(null);
    }

    @ApiOperation(value = "查询所有公告")
    @GetMapping("/selectAllByAnc_status")
    public Message selectAllByAnc_status(){
        return Message.success(null).add(announcementService.selectAllAnnouncement());
    }

    @ApiOperation(value = "分页查询-所有公告")
    @GetMapping("/pagingSearchAllAnnouncement")
    public Message pagingSearchAllAnnouncement(@RequestParam Integer pageNum,@RequestParam Integer size){
        return announcementService.PagingSearch(pageNum, size);
    }
}
